﻿{extend name="public:base" /}


{block name="css"}
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css"/>
<link rel="stylesheet" type="text/css" href="__ADMIN__/css/style.css">{/block}

{block name="content"}

<div class="row list" style="margin-top: 20px">
    <div class="col-lg-12">
        <div class="ibox">
            <div class="ibox-title" style="font-size: 20px">
                当前活动
            </div>
            <div class="ibox-content">
                <div class="table-responsive">
                    <table class="table table-striped">
                        <thead>
                        <tr>
                            <th>抽奖类型</th>
                            <th>抽奖条件</th>
                            <th>活动时间段</th>
                            <th>抽奖奖励</th>
                            <th>开启状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td>{$info.type == 1 ? '单品满额抽奖' : '下单加'. $info.add_price .'元抽奖'}</td>
                            <td>{$info.type == 1 ? '单品满'. $info.full_price .'元抽奖' : '下单加'. $info.add_price .'元抽奖'}</td>
                            <td>{$info.time}</td>
                            <td>
                                {volist name="info.coupon_name" id="vo"}
                                {$vo.name}<br/>
                                {/volist}
                            </td>
                            <td>{$info.status_text}</td>
                            <td>
                                {if $info.status == 0}
                                <a href="{:url('startActivity', ['id' => $info.id])}" class="btn btn-white btn-sm ajax-operate"><i class="iconfont icon-edit"></i> 开启活动
                                </a>
                                {/if}
                                {if $info.status == 1}
                                <a href="{:url('endActivity', ['id' => $info.id])}" class="btn btn-white btn-sm ajax-operate"><i class="iconfont icon-edit"></i> 结束活动
                                </a>
                                {/if}
                                {if $is_edit}
                                <a href="javascript: void(0)" class="btn btn-white btn-sm" onclick="editActivity()"><i class="iconfont icon-edit"></i> 编辑
                                </a>
                                {/if}
                                <a href="{:url('delActivity', ['id' => $info.id])}" class="btn btn-white btn-sm ajax-del"><i class="iconfont icon-trash"></i> 删除
                                </a>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    {if !empty($list)}{$list->render()}{/if}
                </div>

            </div>
        </div>
    </div>
</div>

<div class="row set">
    <div class="col-lg-12">
        <div class="ibox ">
            <form action="post" class="ibox-content">
                <div class="box-item">
                    <div class="form-group row layui-form">
                        <label class="col-lg-1 col-form-label">抽奖类型：</label>
                        <div class="col-lg-3">
                            <input type="radio" lay-filter="type" class="type_radio" name="type" value="1" title="单品满额抽奖" {$info.type != 2 ? 'checked' : ''}>
                            <input type="radio" lay-filter="type" class="type_radio" name="type" value="2" title="下单加1元抽奖" {$info.type == 2 ? 'checked' : ''}>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                </div>

                <div class="box-item full_price">
                    <div class="form-group row">
                        <label class="col-sm-1 col-form-label">单品满额金额</label>
                        <div class="col-sm-3">
                            <input type="number" class="form-control" name="full_price" value="{$info.full_price}" placeholder="请输入单品满额金额">
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                </div>

                <div class="box-item">
                    <div class="form-group row">
                        <label class="col-sm-1 col-form-label">活动时间段</label>
                        <div class="col-sm-3">
                            <input placeholder="请选择开始时间" type="text" name="time" value="{$info.time}" class="form-control form-control-lg time" readonly>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                </div>

                <div class="box-item">
                    <div class="form-group row layui-form">
                        <label class="col-sm-1 col-form-label">抽奖奖励
                            <br>
                            <small class="text-navy">请选择3-6个实物券</small>
                        </label>
                        <div class="col-sm-6">
                            {volist name="lottery_coupon_list" id="vo"}
                            <input type="checkbox" class="coupon_name" name="lottery_coupon_ids[]" value="{$vo.id}" title="{$vo.name}" lay-filter="coupon_name" {:in_array($vo.name, $info.coupon_name) ? 'checked' : ''}>
                            {/volist}
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                </div>

                <input type="hidden" name="shop_id" value="{$shop_id}">
                <input type="hidden" name="id" value="{$info['id']}">

                <div class="form-group row">
                    <div class="col-sm-4 col-sm-offset-2">
                        <button type="button" class="btn btn-w-m btn-primary ajax-post">保存</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

{include file="public/cropper-img-mask" cropper_uploaded_img_ids="cropper_uploaded_img_ids" cropper_uploaded_img_paths="cropper_uploaded_img_paths" crop_preview_box="crop-preview-box" /}

{include file="public/preview-img-mask" swiper-id="cropper-preview" /}

{/block}

{block name='js'}
<script src="/static/laydate/laydate.js"></script>
<script src="__STATIC__/layui/layui.js"></script>
<script>
    laydate.render({
        elem: '.time', //指定元素
        type: 'datetime',
        range: true
    });

    $(function () {
        var type = $('.type_radio').val();
        if (type == 1) {
            $('.full_price').show();
        } else {
            $('.full_price').hide();
        }

        var id = `{$info.id}`;
        if (id > 0) {
            $('.list').show();
            $('.set').hide();
        } else {
            $('.list').hide();
            $('.set').show();
        }
    })

    function editActivity() {
        $('.list').hide();
        $('.set').show();
    }

    layui.use(function () {
        var form = layui.form;
        var layer = layui.layer;

        form.on('radio(type)', function (data) {
            var type = data.value;
            if (type == 1) {
                $('.full_price').show();
            } else {
                $('.full_price').hide();
            }
        })

        // checkbox 事件
        form.on('checkbox(coupon_name)', function (data) {
            /*var elem = data.elem; // 获得 checkbox 原始 DOM 对象
            var checked = elem.checked; // 获得 checkbox 选中状态
            var value = elem.value; // 获得 checkbox 值
            var othis = data.othis; // 获得 checkbox 元素被替换后的 jQuery 对象*/

            var len = $(".coupon_name:checked").length;
            if (len > 6) {
                $(data.elem).next().attr("class", "layui-unselect layui-form-checkbox");
                $(data.elem).prop("checked", false);
                layer.msg('最多只能选6项！', {icon: 5});
                return false;
            }
        })
    })
</script>{/block}
